package com.weather.quartz.config;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.weather.quartz.job.EmailJob;

@Configuration
public class QuartzConfig {
	
	
	@Bean
	public JobDetail printEmailJobDetail() {
		
		return JobBuilder.newJob(EmailJob.class) // 创建业务类JobDetail
				.withIdentity("EmailJob")        // 给JobDetail取一个
				.usingJobData("to", "yyy@qq.com")
				.usingJobData("cc", "xxx@qq.com") // 关联键值对
				.storeDurably()                  // 无Trigger关联也不删除JobDtail
				.build();
	}
	
	
	@Bean
	public  Trigger printEmailTrigger() {
		
		return TriggerBuilder.newTrigger()
				.forJob(printEmailJobDetail())
				.withIdentity("quartzTaskService", "group1")
				.withSchedule(CronScheduleBuilder.cronSchedule("0 0 7 * * ?"))
				.build();
	}

}
